import Vue from 'vue'

// css样式重置
import 'normalize.css/normalize.css' // A modern alternative to CSS resets

import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import i18n from '@/lang/index.js'

import '@/styles/index.scss' // global css

import App from './App'
import store from './store'
import router from './router'

import '@/icons' // icon
import '@/permission' // permission control
import MyPlugin from '@/components'
// 2.使用插件
Vue.use(MyPlugin)

// 自定义指令
// Vue.directive('自定义指令名字', {//  配置项})
/* <input v-focus /> */

Vue.directive('focus', {
  // el就是dom
  inserted: function(el, bindings) {
    el.focus()
    el.style.backgroundColor = bindings.value
    console.log('focus', el, bindings)
  }
})

/*
  <el-button v-allow="'import_excel'" />
  目标效果是:
      如果在vuex的points中，没有找到'import_excel' 就移除这个按钮

*/
Vue.directive('allow', {
  // el就是dom
  inserted: function(el, bindings) {
    console.log('v-allow', el, bindings.value)
    console.dir(el)
    // if(vuex的points中没有找到'import_excel') {
    const points = store.state.user.userInfo.roles.points

    if (!points.includes(bindings.value)) {
      console.log('要删除元素')
      el.parentNode.removeChild(el)
    }
  }
})
// (function() {
//   let i = 1
//   const log = console.log
//   console.log = function() {
//     // debugger
//     log.apply(this, [i++, Date.now(), ...arguments])
//   }
// })()

// console.log('abc')
/**
 * If you don't want to use mock-server
 * you want to use MockJs for mock api
 * you can execute: mockXHR()
 *
 * Currently MockJs will be used in the production environment,
 * please remove it before going online ! ! !
 */
// if (process.env.NODE_ENV === 'production') {
//   const { mockXHR } = require('../mock')
//   mockXHR()
// }
console.log('环境变量的值是', process.env)
// set ElementUI lang to EN
// Vue.use(ElementUI, { locale })
// 如果想要中文版 element-ui，按如下方式声明
Vue.use(ElementUI)

Vue.config.productionTip = false

new Vue({
  el: '#app',
  router, // $router
  store, // $store
  i18n, // $t
  render: h => h(App)
})
